from app.models.Model import ToUsers
from app.models.BaseModel import *
from sqlalchemy_serializer import SerializerMixin
from sqlalchemy import desc, asc


class UserModel(ToUsers, BaseModel, SerializerMixin):

    @staticmethod
    def getUser(filters, order='id desc', field=()):
        '''
        find user
        :param filters: set
        :param order: str
        :param field: tuple
        :return: dict
        '''
        rows = BaseModel().getOne(UserModel, filters, order, field)
        return rows

    @staticmethod
    def updateUser(filters: set, data: dict) -> bool:
        '''
        update user
        :param filters: set
        :param data: dict
        :return: bool
        '''
        status = BaseModel().edit(UserModel, data, filters)
        return status

    @staticmethod
    def deleteUser(filters: set) -> int:
        '''
        delete user
        :param filters: set
        :return: int
        '''
        status = BaseModel().delete(UserModel, filters)
        return status

    @staticmethod
    def getAllUser(filters: set = None, order: str = 'id asc', field: tuple = (), limit: int = 0) -> list:
        '''
        get user list all
        :param filters: set
        :param order: str
        :param field: tuple
        :param limit: int
        :return: list
        '''
        rows = BaseModel().getAll(UserModel, filters, order, field, limit)
        return rows

    @staticmethod
    def addUser(data):
        rows = BaseModel().add(UserModel, data)
        return rows
